package com.ltkj.system.api.factory;

import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.system.api.domain.CommAttachment;
import com.ltkj.system.api.domain.CommAttachmentQueryVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.ltkj.common.core.domain.R;
import com.ltkj.system.api.RemoteFileService;
import com.ltkj.system.api.domain.SysFile;

import java.util.List;

/**
 * 文件服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);

    @Override
    public RemoteFileService create(Throwable throwable)
    {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteFileService()
        {
            @Override
            public R<SysFile> upload(MultipartFile file)
            {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }

            @Override
            public R<CommAttachment> uploadPlus(MultipartFile file, String zoom, String infoCode, Long infoId) {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }

            @Override
            public R<CommAttachment> uploadAttaData(MultipartFile file, String zoom, String infoCode, Long infoId) {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult updateAttaData(Long infoId, String infoCode, String attaIds) {
                return AjaxResult.error("关联文件失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult deletaAtta(Long attaId) {
                return AjaxResult.error("删除文件失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult deletaAttaByInfo(String infoCode, Long infoId) {
                return AjaxResult.error("删除文件失败:" + throwable.getMessage());
            }

            @Override
            public R<List<CommAttachment>> uploadAttaDataMore(List<MultipartFile> files, String zoom, String infoCode, Long infoId) {
                return R.fail("多文件上传文件失败:" + throwable.getMessage());
            }

            @Override
            public List<CommAttachment> selectAtta(Long infoId, String infoCode) {
                return null;
            }

            @Override
            public CommAttachment selectAttaById(Long attaId) {
                return null;
            }

            @Override
            public R<List<CommAttachment>> selectAttaByInfoIds(CommAttachmentQueryVo commAttachmentQueryVo) {
                return null;
            }


        };
    }
}
